package admin;

import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.Vector;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;

import org.exolab.jms.administration.AdminConnectionFactory;
import org.exolab.jms.administration.JmsAdminServerIfc;

public class ListDestinations {
	
	public final static String PROTOCOL = "tcp";
	public final static String IP = "localhost";
	public final static String PORT = "3035";
	public final static String USER = "admin";
	public final static String PASSWORD = "openjms";

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			String url = PROTOCOL+"://"+IP+":"+PORT;
			JmsAdminServerIfc admin = AdminConnectionFactory.create(url, USER, PASSWORD);
			
			Vector<Destination> destinations = admin.getAllDestinations();
			Iterator<Destination> iterator = destinations.iterator();
			while (iterator.hasNext()) {
				Destination destination = (Destination) iterator.next();
				if (destination instanceof Queue) {
					Queue queue = (Queue) destination;
					System.out.println("Queue : " + queue.getQueueName());
				} else {
					Topic topic = (Topic) destination;
					System.out.println("Topic : " + topic.getTopicName());
				}
			}

			admin.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
